<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%>
<%@ page import="xml.response.*"%>
<%@ page import="xml.root"%>
<%@ page import="util.print.printLogCat"%>
<%@ page import="org.sql.table.*"%>
<%@ page import="xml.var"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="jqgrid.jqgrid"%>
<%@ page import="org.util.getNewData"%>
<%@ page import="requestInterFace.Handle.*"%>
<%@ page import="org.util.SerialNumberUtil"%>
<%@ include file="../../util/paramPrint.jsp" %>
<%@ page import="util.check"%>
<%@ page trimDirectiveWhitespaces="true" %> 
<%
String User_ID = request.getParameter("User_ID");
String Product_ID = request.getParameter("Product_ID");
String Price = request.getParameter("Price");
String Info =request.getParameter("Info");//产品描述
String userType=(String)session.getAttribute("User_Type");
root root=new root();
if(userType==null||!userType.equals("1")){
root.setStatus("false");
root.setMsg("权限不够");
//PrintWriter pw = response.getWriter();
//pw.println(root.getXmlString());
//pw.flush();
//return ;
}

 		if(Product_ID==null||User_ID==null||User_ID.equals("")||Product_ID.equals("")){
		root.setStatus("false");
		root.setMsg("请填写正确产品ID和用户ID");
		PrintWriter pw = response.getWriter();
		pw.println(root.getXmlString());
		pw.flush();
		return ;
		}
		
		User_ID=java.net.URLDecoder.decode(User_ID,"UTF-8");
		userProductHandle handle=new userProductHandle();
		if(handle.isHave(User_ID,Product_ID)){
			root.setStatus("false");
			root.setMsg("记录已经存在");
			PrintWriter pw = response.getWriter();
			pw.println(root.getXmlString());
			pw.flush();
			return ;
		}
		userproductinfo1_1 user=new userproductinfo1_1();

		if(User_ID!=null&&(!User_ID.equals(""))){
		 user.setInsertField("User_ID",User_ID);
		 userHandle userHandle=new userHandle();
		if(!userHandle.isHaveUser(User_ID)){
			root.setStatus("false");
			root.setMsg("客户不存在");
			PrintWriter pw = response.getWriter();
			pw.println(root.getXmlString());
			pw.flush();
			return ;
		}
		}
		
		if(Product_ID!=null&&(!Product_ID.equals(""))){
		productHandle productHandle =new productHandle();
		if(!productHandle.isHaveProduct(Product_ID)){
		root.setStatus("false");
			root.setMsg("产品不存在");
			PrintWriter pw = response.getWriter();
			pw.println(root.getXmlString());
			pw.flush();
			return ;
		}
		 user.setInsertField("Product_ID", Product_ID);
		}
		if(Price!=null&&(!Price.equals(""))){
		 if(check.isNumeric(Price)){
		 	user.setInsertField("Price",Price);
		  }else{
		    root.setStatus("false");
			root.setMsg("不是正确的数值");
			PrintWriter pw = response.getWriter();
			pw.println(root.getXmlString());
			pw.flush();
			return ;
		   }
		}else{
			root.setStatus("false");
			root.setMsg("请填写正确的价格");
			PrintWriter pw = response.getWriter();
			pw.println(root.getXmlString());
			pw.flush();
			return ;
		}
		if(Info!=null&&!Info.equals("")){
		 user.setInsertField("Info",Info);
		}
		user.setInsertField("Add_Time",getNewData.GetNowDateAndTime1());
		int row=user.insert();
		root.setRecords(""+row);//设置当前查询到的记录数
		if(row>0){
			root.setStatus("true");
			root.setMsg("添加成功");
		}
		//printLogCat.printlnWriter(root.getXmlString());
		String rep=root.getXmlString();
%>
<%=rep%>

